package jfood.gui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

import jfood.restaurant.RestaurantAgent;

public class MainHole extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2116562818914355508L;
	private RestaurantAgent agent;

	public MainHole(RestaurantAgent agent) {
		this.agent = agent;
		this.addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent we) {
				setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			}
		});

		this.setTitle("Restauracja");
		this.setSize(200, 200);
		this.setResizable(false);
		this.setLocationRelativeTo(null);

		JButton spawnWaiter = new JButton();
		spawnWaiter.setText("Zawołaj kelnera");
		spawnWaiter.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				boolean isWaiterFree = MainHole.this.agent.spawnWaiter();
				if (!isWaiterFree) {
					JOptionPane.showMessageDialog(MainHole.this, "Wszyscy kelnerzy są aktualnie zajęci. Poczekaj chwilę", "Kelnerzy zajęci", JOptionPane.ERROR_MESSAGE);
				}
			}
		});
		
		this.add(spawnWaiter);
	}
}
